package com.nowcoder.code.hjnc;

public class NC19 {

    public static void main(String[] args) {
//        System.out.println(new NC19().maxsumofSubarray(new int[]{1, -2, 3, 5, -2, 6, -1}));
        System.out.println(new NC19().maxsumofSubarray(new int[]{1}));
    }


    public int maxsumofSubarray(int[] arr) {

        int max = 0;
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] + sum > 0) {
                sum = arr[i] + sum;
                if (sum > max) {
                    max = sum;
                }
            } else {
                sum = 0;
            }
        }
        return max;
    }

}
